# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
### Reducing Prejudice and Support for Religious 
### Nationalism Through Conversations on WhatsApp 

### Author: Rajeshwari Majumdar
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# File:     supp_experience.R
# Purpose:  analyze outcomes related to study experience for Appendix A 
#           (Ethical considerations) and Appendix B (Study environment)
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# Load data and custom functions 
rm(list=ls())
load("data/Completes_Merged_Anonymized.RData")
source("code/02_setup_functions.R")


# Overall experience ----
tabyl(d$exper2_overallmcq)
d %>% summarize(mean(exper2_overallmcq, na.rm = TRUE))
d %>% group_by(religion) %>% summarize(mean(exper2_overallmcq, na.rm = TRUE))
d %>% group_by(religion, condition_topic) %>% summarize(mean(exper2_overallmcq, na.rm = TRUE))
d %>% group_by(condition_topic) %>% summarize(mean(exper2_overallmcq, na.rm = TRUE))


# Self-reported incidents during the conversations ----
# (namely: arguing, learning something new, changing mind, feeling inspired)
d$exper1_incident_argued = as.numeric(grepl("argued", d$exper1_incident))
d$exper1_incident_learned = as.numeric(grepl("learned", d$exper1_incident))
d$exper1_incident_changedmind = as.numeric(grepl("changedmind", d$exper1_incident))
d$exper1_incident_inspired = as.numeric(grepl("inspired", d$exper1_incident))

## Arguing
d %>% summarize(mean(exper1_incident_argued))
d %>% group_by(condition_topic) %>% summarize(mean(exper1_incident_argued))
d %>% group_by(condition_pair) %>% summarize(mean(exper1_incident_argued))

## Arguing and other feelings
d %>% group_by(exper1_incident_argued) %>% summarize(mean(exper1_incident_learned))
d %>% group_by(exper1_incident_argued) %>% summarize(mean(exper1_incident_changedmind))
d %>% group_by(exper1_incident_argued) %>% summarize(mean(exper1_incident_inspired))


# Muslims' feelings ----
## No significant changes in feelings about Msulims or Hindus (pre vs post)
t.test(
  d %>% filter(religion == "Muslim") %>% select(feelth_muslim) %>% pull(),
  d %>% filter(religion == "Muslim") %>% select(post.feelth_muslim) %>% pull(),
)
t.test(
  d %>% filter(religion == "Muslim") %>% select(feelth_hindu) %>% pull(),
  d %>% filter(religion == "Muslim") %>% select(post.feelth_hindu) %>% pull(),
)

## No significant variation in approval of religious nationalism (comparing topic conditions)
fn_reg_more(depvars = c("twt_HinduNation_q1","twt_Hijab_q1"), 
              who = "Muslims", treat = "condition_topic", 
              data = d, print = "full" )
